import { useReactive } from "ahooks";

const useCheckProxyServer = () => {
    const state = useReactive({
        loading: false,
    });

    const checkProxyServer = async (proxyUrl, callback) => {
        state.loading = true;
        try {
            let response = await fetch(proxyUrl);
            if (response.ok) {
                const text = await response.text();
                if (text === "ok") return true;
            }
        } catch (error) {}
        state.loading = false;
        return false;
    };

    return { ...state, checkProxyServer };
};

export default useCheckProxyServer;
